﻿<%@ Page Title="" Language="C#" MasterPageFile="~/layout/admin.Master" AutoEventWireup="true" CodeBehind="EditProduct.aspx.cs" Inherits="SinhNhat.admin.EditProduct" %>
<%@ Register Assembly="CKEditor.NET" Namespace="CKEditor.NET" TagPrefix="CKEditor" %>

<asp:Content ID="Content1" ContentPlaceHolderID="ContentMain" runat="server">

    <script type="text/javascript">
        function Valid() {
            var valid = true;


            var errorStr = "";
            var txtName = document.getElementById("<%=txtName.ClientID %>");
            var txtPrice = document.getElementById("<%=txtPrice.ClientID %>");
            //ctl00_ContentMain_txtDescription
            var txtContent = CKEDITOR.instances.<%=txtDescription.ClientID %>.getData();

            if (txtName.value == '') {
                txtName.setAttribute('class', 'textValid');
                errorStr += "<li style='color:red;'>Nhập tên sản phẩm</li>";
                txtName.focus();
                valid = false;
            }
            else {
                txtName.setAttribute('class', '');
            }

//            if (txtURL.value == '') {
//                txtURL.setAttribute('class', 'textValid');
//                errorStr += "<li style='color:red;'>NhậpURL</li>";
//                txtURL.focus();
//                valid = false;
//            }
//            else {
//                txtURL.setAttribute('class', '');
//            }

            if (txtContent == '') {
                errorStr += "<li style='color:red;'>Nhập nội dung</li>";
                valid = false;
            }

            if (txtPrice.value == '') {
                txtPrice.setAttribute('class', 'textValid');
                errorStr += "<li style='color:red;'>Nhập giá</li>";
                txtPrice.focus();
                valid = false;
            }
            else if(isNaN(txtPrice.value)){
                txtPrice.setAttribute('class', 'textValid');
                errorStr += "<li style='color:red;'>Giá bán không đúng</li>";
                txtPrice.focus();
                valid = false;
            }
            else if((parseFloat(txtPrice.value)) < 0){
                txtPrice.setAttribute('class', 'textValid');
                errorStr += "<li style='color:red;'>Giá bán không đúng</li>";
                txtPrice.focus();
                valid = false;
            }
            else {
                txtPrice.setAttribute('class', '');
            }
            
            var myselect = document.getElementById("<%=lbCategory.ClientID %>");            
            var i;
            for (i=0; i < myselect.options.length; i++){
                if (myselect.options[i].selected==true){
                    break;
                }
            }

            if(i == myselect.options.length){
                myselect.setAttribute('class', 'textValid');
                errorStr += "<li style='color:red;'>Chọn loại sản phẩm</li>";
                myselect.focus();
                valid = false;
            }
            else
            {
                myselect.setAttribute('class', '');
            }

            if (valid == false) {
                errorStr = "<ul>" + errorStr + "</ul>";
            }

            document.getElementById("divError").innerHTML = errorStr;
            return valid;
        }
    </script>
        

    <asp:HiddenField ID="hdServiceID" runat="server" />
    <asp:HiddenField ID="hdUrlOld" runat="server" />

    <h2>
        <asp:Label ID="lblHeader" runat="server" />
    </h2>

    <table>
        <tr>
            <td style="width:100px;">Tên sản phẩm</td>
            <td>
                <asp:TextBox ID="txtName" runat="server" Width="500px" />
            </td>
        </tr>
        <%--<tr>
            <td>URL</td>
            <td>
                <asp:TextBox ID="txtUrl" runat="server" Width="500px" />
            </td>
        </tr>--%>
        <tr>
            <td>Hình ảnh</td>
            <td>
                <asp:FileUpload ID="fuProduct" runat="server" />
                <asp:Image ID="imgProduct" runat="server" Visible="false" Width="300px" />
                <asp:Label ID="lblErrorImg" runat="server" ForeColor="Red" Visible="false" Text="Image is not correct" />
            </td>
        </tr>
        <tr>
            <td>Mô tả</td>
            <td>
                <CKEditor:CKEditorControl ID="txtDescription" runat="server" Width="666px" Height="400px"></CKEditor:CKEditorControl>
            </td>
        </tr>
        <tr>
            <td>Loại sản phẩm</td>
            <td>
                <asp:ListBox ID="lbCategory" runat="server" Width="300px" Height="300px" />
            </td>
        </tr>
        <tr>
            <td>Giá</td>
            <td>
                <asp:TextBox ID="txtPrice" runat="server" Width="500px" />
            </td>
        </tr>
        <tr>
            <td>Còn hàng</td>
            <td>
                <asp:CheckBox ID="chkInStock" runat="server" />
            </td>
        </tr>
        <tr>
            <td></td>
            <td>
                <div id="divError"></div>
                <asp:Literal ID="lblError" runat="server" Text="<ul><li style='color:red;'>URL đã tồn tại</li></ul>" Visible="false" Mode="PassThrough" />
            </td>
        </tr>
        <tr>
            <td align="center" colspan="2">
                <asp:Button ID="btnSave" runat="server" OnClientClick="return Valid();" Text="Save" CssClass="button_colour round_all" />

                <%--<button id="btnSave" class="button_colour round_all" runat="server">
                    <img height="24" width="24" alt="Bended Arrow Right" src="/data/theme/admin/image/Bended_Arrow_Right.png">
                    <span>Lưu kết quả</span>
                </button>--%>
            </td>
        </tr>
    </table>

</asp:Content>
